﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YJKRevitDimension.LevelDimension;
using YJKRevitKernel.ElementSearchUtility.LinkDocumentSuite;
using YJKPatternSign.StairsRoomSection.Kit;

namespace YJKPatternSign.StairsRoomSection.SignElems
{
	public class StairsLandingSign
	{
		public StairsLandingSign(ExternalCommandData commandData, Autodesk.Revit.DB.Document Doc, List<BaseLinkDocumentResultBean> lstStairs, Dictionary<string, double> DicLayerInfo)
		{
			this.m_commandData = commandData;
			this.m_doc = Doc;
			this.m_lstStairs = new List<BaseLinkDocumentResultBean>();
			this.m_lstStairs.AddRange(lstStairs);
			this.m_DicLayerInfo = DicLayerInfo;
		}

		public bool Sign()
		{
			LevelDimensionManager dimManager = new LevelDimensionManager(this.m_commandData);
			foreach (BaseLinkDocumentResultBean baseLinkDocumentResultBean in this.m_lstStairs)
			{
				Stairs stairs = baseLinkDocumentResultBean.UseElement as Stairs;
				Document document = stairs.Document;
				Transform totalTransform = baseLinkDocumentResultBean.GetTotalTransform();
				double baseElevation = stairs.BaseElevation;
				foreach (ElementId elementId in (stairs.GetStairsLandings() as List<ElementId>))
				{
					StairsLanding stairsLanding = document.GetElement(elementId) as StairsLanding;
					double num = baseElevation + stairsLanding.BaseElevation;
					num = SignCommon.TransformDouble(totalTransform, num);
					CurveLoop footprintBoundary = stairsLanding.GetFootprintBoundary();
					CurveArray curveArray = new CurveArray();
					foreach (Curve curve in footprintBoundary)
					{
						curveArray.Append(curve);
					}
					XYZ xyz = YJKRevitTools.Centroid(curveArray);
					xyz = totalTransform.OfPoint(xyz);
					xyz = new XYZ(xyz.X, xyz.Y, num);
					SignCommon.CreateElevatorDim(dimManager, this.m_doc, xyz, num, this.m_DicLayerInfo);
				}
			}
			return true;
		}

		private ExternalCommandData m_commandData;

		private Document m_doc;

		private List<BaseLinkDocumentResultBean> m_lstStairs;

		private Dictionary<string, double> m_DicLayerInfo;
	}
}
